Skip to content

feat(routing): add opt-in reviewed configuration snapshots - #24

Merged
ALikesToCode merged 1 commit into
feat/prompt-templatesfrom
feat/config-snapshots
Oct 9, 2026
Merged

ALikesToCode merged 1 commit into
feat/prompt-templatesfrom
feat/config-snapshots

Conversation

@ALikesToCode

Copy link
Copy Markdown
Owner

Summary

Adds reviewed configuration snapshots for auto-routes behind CONFIG_SNAPSHOTS_ENABLED, which defaults to false. While the flag is off, every snapshot path returns 404, and auto-route saves keep their current payload, storage and response.

  • POST /admin/config/snapshots stores an immutable patch of route IDs and candidate model IDs against a base_revision. It does not activate anything.
  • GET /admin/config/snapshots lists the current revision, snapshot metadata and the latest 100 apply records.
  • GET /admin/config/snapshots/<id>/diff shows before and after model lists, 20 routes per page.
  • POST /admin/config/snapshots/<id>/apply needs confirm: true and the current revision. A single D1 batch checks the revision and the exact stored route state, writes the routes, bumps the revision and appends an audit record. A stale review returns 409. A failed route write rolls the whole batch back.
  • Every snapshot path uses the dashboard session, admin check and CSRF protection, and responses are no-store.
  • Only route IDs and candidate model IDs are accepted. Credential-shaped identifiers and retired seeded orders are refused.
  • To roll back, create and apply a new snapshot with the previous order. Each domain keeps at most 100 snapshots.
  • An apply clears this Container's route cache. Other Containers pick up the change within the existing 30-second cache interval.

Details are in docs/config-snapshots.md.

Stacked on #23

This branch is based on feat/prompt-templates (#23) so that migration 0015_config_snapshots.sql follows 0014_prompt_templates.sql. Merge #23 first; GitHub then retargets this PR to main.

Before merging to main

Apply the D1 migrations first. A push to main does not apply them, and /ready reports d1_schema_missing until the three new tables exist:

npx wrangler d1 migrations apply multillm-intelligence --remote

With the flag on, ordinary auto-route saves also advance the revision. If the tables are missing, they fail closed with JSON 503, as do the snapshot routes.

Shared registrations

  • Added tests/test_config_snapshots_worker.mjs to test:worker.
  • Added CONFIG_SNAPSHOTS_ENABLED to the Container env keys.
  • Added config_snapshot_revisions, config_snapshots and config_snapshot_applications to REQUIRED_D1_TABLES.
  • Added the three Flask routes to the secret firewall inventory.

Tests

  • Full Python suite: 2,499 passed. ruff, mypy and bandit are clean.
  • npm run test:worker: 1,194 passed. The Worker tests run the migrations in Miniflare D1, including the missing-migration case. cf:migrations:check, test:deploy, free routes, client headers and the wrangler deploy --dry-run bundle all pass.
  • tests/test_frontend_build.mjs fails locally because @tailwindcss/cli is not installed. It fails the same way on main.

The README line for this feature is added by the Wave 2 integration PR.

CONFIG_SNAPSHOTS_ENABLED (default off) adds admin snapshots of auto-route candidate orders with a paginated diff and a confirmed apply. Apply runs as one D1 batch that checks the revision and stored route state, writes the routes, bumps the revision and appends an audit record, so a stale review returns 409. Rollback is a new snapshot. Snapshots use migration 0015 and fail closed with JSON 503 when its tables are missing.
@coderabbitai

coderabbitai Bot commented Oct 8, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7701ed15-9136-4918-b955-9c2664e00f84

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-08T21:03:22.854409Z 287f929 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
multillm-proxy 287f929 Oct 08 2026, 08:58 PM

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 287f929820

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

response = client.get("/admin/config/snapshots")
checks.assertEqual(response.status_code, 302)
with client.application.test_request_context():
checks.assertEqual(response.headers["Location"], url_for("login", next="/admin/config/snapshots"))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Match the redirect emitted by login_required

In this unauthenticated scenario, login_required in route_helpers.py redirects with url_for("login") and does not supply a next argument, so the response location is /login, not /login?next=/admin/config/snapshots. This new assertion will therefore fail on every full Python test run; either assert the bare login URL or update the decorator to preserve the destination.

Useful? React with 👍 / 👎.

Comment on lines +176 to +177
result = call("snapshot_apply", id=identifier, current_revision=body["current_revision"],
confirm=True, actor=actor_identity(user))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Revalidate stored candidate orders before applying

When a snapshot survives a deployment that adds its candidate order to LEGACY_DEFAULT_AUTO_ROUTES, the creation-time check no longer protects this apply path: the stored configuration is applied without validation against the current legacy list, while AutoRouteService._durable_routes subsequently replaces that exact persisted order with DEFAULT_AUTO_ROUTES. The endpoint can consequently return applied: true and append an audit revision even though the reviewed order never becomes effective; revalidate the snapshot against the current defaults during apply or invalidate snapshots that have become retired.

Useful? React with 👍 / 👎.

user = require_admin_dashboard_user()
if request.method == "GET":
return jsonify(config_snapshots.call("snapshot_list"))
return jsonify(config_snapshots.create(request.get_json(silent=True), user, app.config["API_BASE_URLS"])), 201

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Enforce the snapshot byte limit before JSON parsing

The create handler reads and parses the entire request before installing any snapshot-specific body limit, so it inherits the application's 32 MiB default rather than the advertised 256 KiB bound. An authenticated request near that limit is materialized by get_json, then serialized and encoded again by validate_configuration before it can return 413, which can consume several times the request size per worker; set request.max_content_length in the early snapshot gate, as the prompt-template routes do, so oversized snapshots are rejected before parsing.

Useful? React with 👍 / 👎.

Comment thread worker/auto-routes-d1.mjs
Comment on lines +121 to +124
db.prepare(`INSERT INTO auto_routes (route_id, candidates, updated_at)
SELECT ?, ?, ? WHERE changes()=1
ON CONFLICT(route_id) DO UPDATE SET candidates=excluded.candidates, updated_at=excluded.updated_at`)
.bind(body.route_id, JSON.stringify(body.candidates), body.updated_at)];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve the 200-route bound in ordinary saves

When snapshots are enabled and auto_routes already contains 200 rows, saving a new route through this newly selected path unconditionally inserts a 201st row and still returns stored: true. Ordinary reads are capped at 200 rows, so one persisted route is then omitted based on sort order, and applySnapshot rejects every later snapshot because its count predicate starts above MAX_ROUTES, even when the patch only updates existing routes. Add the same count-and-existence guard used by snapshot apply to revisionedSave.

Useful? React with 👍 / 👎.

@ALikesToCode
ALikesToCode merged commit 6754e0e into feat/prompt-templates Oct 9, 2026
5 of 7 checks passed
@ALikesToCode
ALikesToCode deleted the feat/config-snapshots branch October 26, 2026 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant